package gang.org.springframework.boot.autoconfigure.aop;

import gang.org.springframework.framework.annotation.GBean;
import gang.org.springframework.framework.annotation.GConfiguration;
import gang.org.springframework.framework.aop.config.GangAopConfigUtils;
import gang.org.springframework.framework.beanfactorypostprocessor.GangBeanFactoryPostProcessor;
import gang.org.springframework.framework.support.GangBeanDefinitionRegistry;

/**
 * 类说明：gang.chen springboot深度实践
 *
 * @author gang.chen
 * @since 2022/5/15
 */
@GConfiguration
public class GangAopAutoConfiguration {


    @GConfiguration
    public static class GangClassProxyingConfiguration{

        /**
         * 业务意义
         * 1）forceAutoProxyCreatorToUseClassProxying 创建一个函数式接口实例，Lambda实例
         * 2) Lambda实例，基本质是一个BeanFactoryPostProcessor
         * */
        @GBean
        public static GangBeanFactoryPostProcessor forceAutoProxyCreatorToUseClassProxying(){
            return (beanFactory -> {
                if (beanFactory instanceof GangBeanDefinitionRegistry) {
                    GangBeanDefinitionRegistry registry = (GangBeanDefinitionRegistry) beanFactory;
                    GangAopConfigUtils.registerAutoProxyCreatorIfNecessary(registry);
                    GangAopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
                }
            });
        }

    }
}
